<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'base.item.class.php');

class FormBase extends BaseItemBase {
	
	//constructor
	function FormBase() {
		parent::BaseItemBase();
		
		$this->table = 'pp_forms';
		$this->prefix = 'forms_';
		
		$this->filter_fields = array('cid:=');
	}
	
	//methods
	function getItemsDetail($filter = '', $check = 0, $limit = true) {
		$items = $this->getItems($filter, $check, $limit);
		for($i=0, $n=sizeof($items); $i<$n; $i++) {
			$items[$i]['items'] = $this->getFormItems($items[$i]['id']);
		}
		
		return $items;
	}
	
	function getFormItems($fid) {
		include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/form/form.item.class.php');
		$mObj = new FormItemBase();
		$mObj->format = true;
		$mObj->owner = $fid;
		$items = $mObj->getItems('', 0, false);
		for($i=0, $n=sizeof($items); $i<$n; $i++) {
			if( $items[$i]['type'] == 'select' || $items[$i]['type'] == 'radio' || $items[$i]['type'] == 'checkbox' ) {
				$items[$i]['value'] = util_text_split($items[$i]['value'], true);	
			}
		}
		
		return $items;
	}
}
//
?>